/**************************************************************************
 * @doc ACCUM
 * @module ACCUM.H - Header code for the accumulator handling functions.|  
 * Header code for the accumulator handling functions.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team (I_SP2000).
 * <nl>Notes       :
 *
 * @head3 ACCUM Functions |
 * @index | ACCUM
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 * 
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form 
 * or by any means whether electronic, mechanical, magnetic, optical, 
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 * $log: /Base-99996/Accum/accum.h $
 * ------------------------------------------------------------------------
 ********************************************************************************/
#ifndef ACCUM

#include <define.h>
#include <transact.h>
#include <print.h>
#include <report.h>
#include <sizes.h>

#define ACCUM

/* defines for set of totals   	*/
/*#define ALL_TOTALS  			2*/

#define MAX_ISSUERS		50
#define MAX_ACCUM_TYPES	4	// @msg #define MAX_ACCUM_TYPES | CREDIT, DEBIT, VOID_CREDIT, VOID_DEBIT (4)
#define MAX_TOTAL_SETS	2	// @msg #define MAX_TOTAL_SETS	| CREDIT_CARD, DEBIT_CARD (2)

#define REFUND_TRAN         0 // @msg #define REFUND_TRAN         | 0
#define SALE_TRAN           1 // @msg #define SALE_TRAN           | 1
#define VOID_REFUND_TRAN    2 // @msg #define VOID_REFUND_TRAN    | 2
#define VOID_SALE_TRAN      3 // @msg #define VOID_SALE_TRAN      | 3

// @struct TagACCUM_TOTALS | Accumulator Totals Structure
typedef struct TagACCUM_TOTALS
{
	long lnCount[MAX_ACCUM_TYPES];     // @field Count
	long lnTipCount[MAX_ACCUM_TYPES];  // @field Tipped Transaction Count
	double dbAmount[MAX_ACCUM_TYPES];    // @field Amount
	double dbTip[MAX_ACCUM_TYPES];       // @field Tip Amount
	double dbTax[MAX_ACCUM_TYPES];       // @field Tax Amount
	double dbCashBack[MAX_ACCUM_TYPES];  // @field CashBack Amount
	double dbSurCharge[MAX_ACCUM_TYPES]; // @field Surcharge Amount
	double dbCustom1[MAX_ACCUM_TYPES];   // @field Custom Amount
	double dbCustom2[MAX_ACCUM_TYPES];   // @field Custom Amount
#ifdef CASHCARD_DEFINED		//meca 20041023 -- fixed from cashcard O3750 -- to correct the problem for totals report -- start
	long lnSaleCnt[MAX_ACCUM_TYPES];			
	long lnCashOutCnt[MAX_ACCUM_TYPES];		
	long lnSurChargeCnt[MAX_ACCUM_TYPES];	
#endif //CASHCARD_DEFINED		//meca 20041023 -- fixed from cashcard O3750 -- to correct the problem for totals report -- end
#ifdef CITI_SING		//jrd 04292005
	double dbCustom3[MAX_ACCUM_TYPES];
	double dbCustom4[MAX_ACCUM_TYPES];
#endif //CITI_SING 
	
} ACCUM_TOTALS;

// @struct TagACCUM_REC | Accumulator Record Structure
typedef struct TagACCUM_REC
{
	ACCUM_TOTALS srTotals[MAX_TOTAL_SETS]; // @field Total Array
} ACCUM_REC;

#define SIZE_ACCUM_REC    (int)sizeof(ACCUM_REC) // @msg #define SIZE_ACCUM_REC      | sizeof(ACCUM_REC)

// @struct TagACCUM_KEY | Accumulator Key Structure
typedef struct TagACCUM_KEY
{
    long     lnRecNum;                 // @field Compulsary for DBFM
    short		 inIssuerNumber;           // @field Issuer Number
} ACCUM_KEY;

#define SIZE_ACCUM_KEY         (int)sizeof(ACCUM_KEY) // @msg #define SIZE_ACCUM_KEY      | sizeof(ACCUM_KEY)

// @struct TagACCUM_SKEY | Accumulator Secondary Key Structure
typedef struct TagACCUM_SKEY 
{   
    int         (*compare_func) ();   // @field Function Pointer
    ACCUM_KEY   accumKey;             // @field ACCUM_KEY Accumulator Key Structure
} ACCUM_SKEY;

// @struct TagACCUM_ISSUER | Accumulator Issuer Structure
typedef struct TagACCUM_ISSUER
{
	VS_BOOL fActiveAccum[MAX_ISSUERS]; // @field Array of function pointers.
} ACCUM_ISSUER;

// @struct TagACCUM_SHIFT | Accumulator Shift Structure
typedef struct TagACCUM_SHIFT
{
	ACCUM_ISSUER srIssuer; // @field Array of function pointers.
} ACCUM_SHIFT;

#define SIZE_ACCUM_SHIFT    (int)sizeof(ACCUM_SHIFT)// @msg #define SIZE_ACCUM_SHIFT      | sizeof(ACCUM_SHIFT)

// @struct ACCUM_VALUES | Accumulator Value Structure
typedef struct
{
    short  inCount;      // @field Count
    short  inTipCount;   // @field Tipped Tran Count
    double dbTotal;      // @field Amount
    double dbTip;        // @field Tip Amount
    double dbTax;        // @field Tax Amount
    double dbCashBack;   // @field CashBack Amount
    double dbSurCharge;  // @field Surcharge Amount
    double dbCustom1;    // @field Custom Field
    double dbCustom2;    // @field Custom Field
#ifdef CASHCARD_DEFINED		//meca 20041023 -- fix from cashcard O3750 -- to correct the problem for totals report -- start
    int inSaleCount;					
    int inCashOutCount;				
    int inSurChrgCount;				
#endif //CASHCARD_DEFINED    		//meca 20041023 -- fix from cashcard O3750 -- to correct the problem for totals report -- end
#ifdef CITI_SING		//jrd 04292005
    double dbCustom3;
    double dbCustom4;	
#endif //CITI_SING 
    
} ACCUM_VALUES;

int inAddAccumFunctions(void);
void vdGetASIFName (char *pchFName);
int inSetASIFile( int inIssuer);
int inResetASIFile(void);
void vdGetAccumFName (char *pchFName);
int inOpenAccum (DB_FILE *psrDBFPtr, char *pchFName);
int inCloseAccum (DB_FILE *psrDBFPtr);
int inAccumCompFn (ACCUM_KEY *psrKey, ACCUM_SKEY *MatchKey);
int inKeyReadAccum (DB_FILE *psrDBFPtr, ACCUM_REC *psrRec, ACCUM_KEY *psrKey, ACCUM_SKEY *psrAccumSKey, long *plnRecNum);
int inSetAccum (TRANSACTION_OBJECT *pobTran, int inAccumType, ACCUM_VALUES srAccum, int inTotalType);
int inUpdateAccum (TRANSACTION_OBJECT *pobTran);
int inCheckBatchTotals (TRANSACTION_OBJECT *pobTran, long *lnCount);
int inUpdateAccumFlow (TRANSACTION_OBJECT *pobTran);
int inSummaryReportOperation (TRANSACTION_OBJECT *pobTran);
int inPrintSummaryReport (PRINTER_OBJECT *obPrinter, TRANSACTION_OBJECT *pobTran);
int inPrintSummaryMiddle (PRINTER_OBJECT *obPrinter, TRANSACTION_OBJECT *pobTran, int *inPrintTop, int inNumberOfMerchants, int inWhichMerchant);
void vdSetSummaryHeaderCondition (int inReportTop, int inGrandTotals);
void vdSetSummaryMiddleCondition (void);
void vdSetSummaryBottomCondition (TRANSACTION_OBJECT *pobTran, int inFormFeed, CARD_TOTS_REC *srTots);
int inBatchTotalsOperation (TRANSACTION_OBJECT *pobTran);
int	inDefaultUpdateAccumValues (TRANSACTION_OBJECT *pobTran, ACCUM_VALUES *psrAccum);
int	inDefaultVoidUpdateAccumValues (TRANSACTION_OBJECT *pobTran, ACCUM_VALUES *psrAccum);
void vdDb2Str (double flValue, char *pchString);

int ACCUM_CODE_CHECK(char * a,char *b,short *  c,char * d,unsigned char * e);

#endif /* ACCUM */
